﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling.Diagrams.ExtensionEnablement;
using Microsoft.VisualStudio.Modeling.ExtensionEnablement;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Ultimate.Features;
using Microsoft.VisualStudio.ArchitectureTools.Extensibility.Uml;
using Microsoft.VisualStudio.ArchitectureTools.Extensibility.Presentation;
using Microsoft.VisualStudio.Uml.Classes;

namespace YasharEl.Infrastructure.ArchitectureTools.AppModeler
{
	[Export(typeof(ICommandExtension))]
	[ClassDesignerExtension]
	public partial class AddEntityExceptions : ModelingLaunchPoint
	{
		[ImportingConstructor]
		public AddEntityExceptions(IFeatureManager featureManager)
			: base(featureManager)
		{
		}

		public override string Text
		{
			get { return "Add Entity Exceptions..."; }
		}
		
		protected override string BindingName
		{
			get { return "AddEntityExceptionsCommandBinding"; }
		}

	    [Import]
        private IDiagramContext Context {get; set;}

	    public override bool CanExecute(IFeatureExtension feature)
	    {
            var result = base.CanExecute(feature);
			if (result)
			{
                var selectedElements = this.Context.CurrentDiagram.GetSelectedShapes<IClass>();                
                if(selectedElements.Count() == 0)
				{
					return false;
				}
				
				this.OnCanExecute(ref result);
			}
			
			return result;
        }
        partial void OnCanExecute(ref bool result);
	}
}

